package model.environmentConfig;

import java.awt.*;
import java.util.*;

import javax.xml.bind.annotation.*;

@XmlRootElement(name = "node")
@XmlAccessorType(XmlAccessType.FIELD)
public class Node
{
	NodeRectangle displayData = null;
	
	String name = null;
	String operatingSystem = null;
	String externalIPAddress = null;
	String internalIPAddress = null;

	@XmlElementWrapper(name="softwarePackages")
	@XmlElement(name="softwarePackage")
	ArrayList<SoftwarePackage> requiredSoftwarePackages = new ArrayList<SoftwarePackage>();

	@XmlElementWrapper(name="securityZones")
	@XmlElement(name="securityZone")
	ArrayList<SecurityZone> securityZone = new ArrayList<SecurityZone>();

	@XmlElementWrapper(name="organizations")
	@XmlElement(name="organization")
	ArrayList<Organization> responsibleOrganization = new ArrayList<Organization>();

	@XmlElementWrapper(name="contactPersons")
	@XmlElement(name="contactPerson")
	ArrayList<ContactPerson> contactPersons = new ArrayList<ContactPerson>();
	
	NodeState nodeState = NodeState.RUNNING_NOTHING;
	
	public Node(){
		this("", "", "", "", new ArrayList<SoftwarePackage>(), new ArrayList<SecurityZone>(), new ArrayList<Organization>(), new ArrayList<ContactPerson>());
	}
	
	public Node(String name, String opSys, String externalIP, String internalIP, ArrayList<SoftwarePackage> softwarePackages, ArrayList<SecurityZone> zones, ArrayList<Organization> orgs, ArrayList<ContactPerson> people)
	{
		this.name = name;
		this.operatingSystem = opSys;
		this.externalIPAddress = externalIP;
		this.internalIPAddress = internalIP;
		this.requiredSoftwarePackages = softwarePackages;
		this.securityZone = zones;
		this.responsibleOrganization = orgs;
		this.contactPersons = people;
	}
	
	public NodeRectangle getDisplayData(){
		return(displayData);
	}
	
	public void setDisplayData(NodeRectangle displayData){
		this.displayData=displayData;
	}
	
	public String getComputerName()
	{
		return name;
	}
	
	public void setComputerName(String setName)
	{
		name = setName;
	}
	
	public String getOperatingSystem()
	{
		return operatingSystem;
	}
	
	public void setOperatingSystem(String setOpSys)
	{
		operatingSystem = setOpSys;
	}
	
	public String getExternalIPAddress()
	{
		return externalIPAddress;
	}
	
	public void setExternalIPAddress(String setExtIP)
	{
		externalIPAddress = setExtIP;
	}
	
	public String getInternalIPAddress()
	{
		return internalIPAddress;
	}
	
	public void setInternalIPAddress(String setIntIP)
	{
		internalIPAddress = setIntIP;
	}
	
	public ArrayList<SoftwarePackage> getRequiredSoftwarePackages()
	{
		return requiredSoftwarePackages;
	}
	
	public void setRequiredSoftwarePackages(ArrayList<SoftwarePackage> setReqSoftPack)
	{
		requiredSoftwarePackages = setReqSoftPack;
	}
	
	public ArrayList<SecurityZone> getSecurityZone()
	{
		return securityZone;
	}
	
	public void setSecurityZone(ArrayList<SecurityZone> setSecZone)
	{
		securityZone = setSecZone;
	}
	
	public ArrayList<Organization> getResponsibleOrganization()
	{
		return responsibleOrganization;
	}
	
	public void setResponsibleOrganization(ArrayList<Organization> setResOrg)
	{
		responsibleOrganization = setResOrg;
	}
	
	public ArrayList<ContactPerson> getContactPerson()
	{
		return contactPersons;
	}
	
	public void setContactPerson(ArrayList<ContactPerson> setConPer)
	{
		contactPersons = setConPer;
	}
	
	public NodeState getNodeState()
	{
		return nodeState;
	}
	
	public void setNodeState(NodeState setNodeState)
	{
		nodeState = setNodeState;
	}
	
	@Override
	public boolean equals(Object n){
		if(n==null || !(n instanceof Node)){
			return(false);
		}
		
		Node node=(Node)n;
		
		if(this.name!=null){
			if(node.getComputerName()!=null){
				if(this.name.compareToIgnoreCase(node.getComputerName())!=0){
					return(false);
				}
			}
			else{
				return(false);
			}
		}
		if(this.externalIPAddress!=null){
			if(node.getExternalIPAddress()!=null){
				if(this.externalIPAddress.compareToIgnoreCase(node.getExternalIPAddress())!=0){
					return(false);
				}
			}
			else{
				return(false);
			}
		}
		if(this.internalIPAddress!=null){
			if(node.getInternalIPAddress()!=null){
				if(this.internalIPAddress.compareToIgnoreCase(node.getInternalIPAddress())!=0){
					return(false);
				}
			}
			else{
				return(false);
			}
		}
		if(this.operatingSystem!=null){
			if(node.getOperatingSystem()!=null){
				if(this.operatingSystem.compareToIgnoreCase(node.getOperatingSystem())!=0){
					return(false);
				}
			}
			else{
				return(false);
			}
		}
		
		if(!(this.contactPersons.containsAll(node.getContactPerson()))){
			return(false);
		}
		if(!(this.requiredSoftwarePackages.containsAll(node.getRequiredSoftwarePackages()))){
			return(false);
		}
		if(!(this.responsibleOrganization.containsAll(node.getResponsibleOrganization()))){
			return(false);
		}
		if(!(this.securityZone.containsAll(node.getSecurityZone()))){
			return(false);
		}
		
		return(true);
	}
	
}
